package c.x.jy.serviceProxyFactory;

import java.lang.reflect.Method;

import org.springframework.cglib.proxy.Proxy;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class ServicePorxyFactory implements org.springframework.cglib.proxy.InvocationHandler {

	private static ThreadLocal l = new ThreadLocal();

	public Object getInstance(Class z) throws InstantiationException, IllegalAccessException {

		Object t = z.newInstance();
		l.set(t);
		return Proxy.newProxyInstance(ServicePorxyFactory.class.getClassLoader(), z.getInterfaces(), this);

	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("打开事务！！！");

		return method.invoke(l.get(), args);
	}

}
